<template>
  <div>
    <el-table :data="adminData.data" style="width: 100%">
      <el-table-column label="Id" width="250">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row._id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="200">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="角色" width="250">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.status }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" width="250">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.creatTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button :disabled="role==='普通管理员' " size="mini" @click="$router.push('/system/admin/updataadmin/'+scope.row._id)"
            >修改</el-button
          >
          <el-button
            :disabled="role==='普通管理员'"
            size="mini"
            type="danger"
            @click="handleDelete(scope.row._id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[3, 5, 8, 10]"
      :page-size="adminData.pageSize-0"
      :current-page="adminData.currentPage-0"
      layout="total, sizes, prev, pager, next, jumper"
      :total="adminData.total"
    ></el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers("admin");
const {mapMutations:publicMutations} = createNamespacedHelpers("publicStore");
export default {
  data(){
    return{
      role:'超级管理员'
    }
  },
  computed:{
    ...mapState(["adminData"]),
  },
  created(){
    this.findAllAdmins();
    const userInfo = JSON.parse(localStorage.getItem("userInfo"));
    // console.log(userInfo);
    const {role} = userInfo;
    this.role = role;
    this.setNowBreadcrumb("adminlist");
  },
  methods: {
    ...mapActions(["findAllAdmins","delAdmin"]),
    ...mapMutations(["setPageNumber","stePageSize"]),
    ...publicMutations(["setNowBreadcrumb"]),
     handleSizeChange(val){
            this.stePageSize(val);
            console.log(val);
            this.findAllAdmins();
        },
        handleCurrentChange(val){
            this.setPageNumber(val);
            this.findAllAdmins();
        },
    handleDelete(_id) {
      // console.log(_id);
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.delAdmin(_id);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
  },
};
</script>

<style>
</style>